<TABLE WIDTH="780" BORDER="0" CELLSPACING="0" CELLPADDING="0">
	<TR>
		<%#Acknowledge%>
	</TR>
	<TR CLASS="RUNTEXT1">
		<TD colspan="2">
			<%#Notes%>
		</TD>
	</TR>
	<TR VALIGN="TOP" CLASS="RUNTEXT1">
		<TD WIDTH="35%" height=100% valign=middle align=center>
			<iframe src="<%#iframesource%>" width=280 height=230>
			</iframe>
		</TD>
		<TD WIDTH="65%" height=100%>
			<TABLE WIDTH="95%" BORDER="0" CELLSPACING="1" cellpadding="5">
				<TR>
					<TD colspan="6" Class="N-MainBGColor">
						<FONT class="heading3"><B>Select Resources </B></FONT>
					</TD>
				</TR>
				<TR>
					<TD CLASS="RUNTEXT1" colspan="4" align="center">
						<input type="text" size=25 name="txtSearchResource" value="<%#txtSearchResourcevalue%>" class=input1 align="center">
						&nbsp;&nbsp; <input type="submit" name="btnSearchResource" value=" Search Resource " class="button2" align="center" onclick="return ValidateSearch(this);">
					</TD>
				</TR>
				<TR>
					<TD CLASS="RUNTEXT1">&nbsp;</TD>
					<TD CLASS="RUNTEXT1">
						<SELECT name="lstResources" class="select1" multiple style="HEIGHT: 150px;WIDTH:200px" align="center">
							<%#ListResources%>
						</SELECT>
					</TD>
					<TD CLASS="RUNTEXT1" align="middle">
						<INPUT TYPE="button" NAME="btnprojright" VALUE=" >> " onClick="return putToUnselected(this)" class="button2">
						<BR>
						<BR>
						<INPUT TYPE="button" NAME="btnDeleteleadteam" VALUE=" << " onclick="return Delete(this)" class="button2">
					</TD>
					<TD CLASS="RUNTEXT1">
						<SELECT name="lstSelected" multiple style="HEIGHT: 150px;WIDTH:200px" align="center" class="select1">
							<%#SelectedResources%>
						</SELECT>
						<INPUT TYPE="HIDDEN" NAME="frmAdvanceSearchID" VALUE="NoUser" ID="Hidden1"> <INPUT TYPE="HIDDEN" NAME="moduleuserids" VALUE="NoUser" ID="Hidden2">
					</TD>
				</TR>
				<TR>
					<TD colspan="6" CLASS="RUNTEXT1">&nbsp;</TD>
				</TR>
				<TR>
					<TD Class="N-MainBGColor" align="center" colspan="6">
						<INPUT TYPE="submit" NAME="btnsave" VALUE="   Proceed  " onclick="return ValidateForm(this);" class="button2">
						<INPUT TYPE="HIDDEN" NAME="getRemoveId" value="" ID="Hidden3"> <input type="hidden" name="checkuserid" value="" ID="Hidden4">
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
</TABLE>
<script>
SortListItems();
function SortListItems()
{

 var sorteditemsarray = new Array();
 var itemsarray = new Array();
 var selObject=document.getElementsByTagName("select")["lstResources"];
 var selitemscount = selObject.options.length;

 for(i=0; i<selitemscount; i++)
    itemsarray[i] = selObject.options[i].text + "|" + selObject.options[i].value;

 itemsarray.sort();

 for(i=0; i<selitemscount; i++)
 {
     sorteditemsarray = itemsarray[i].split("|");

     selObject.options[i].text     = sorteditemsarray[0];
     selObject.options[i].value    = sorteditemsarray[1];

 }
}
function putToUnselected(buttonobj)
{
	//alert(buttonobj)
	var selvalue,seltext,ResourcesListed,ResourcesSelected,pos,checkFlag
	var arrLookup = new  Array();
	var arrTbox  = new Array() ;

	var flag = false;
	checkFlag=false;

	// checking the caption of the button clicked
	//depending the caption the direction of the data flow is decided.
	//alert message when >> button is clicked without selecting a project
	//if the flow is from projectuser to moduleuser.
	if(buttonobj.value==' >> ' && buttonobj.name=='btnprojright')
		{
			ResourcesListed = document.getElementsByTagName("select")["lstResources"]
			ResourcesSelected = document.getElementsByTagName("select")["lstSelected"]

		}

	//LOOPING THROUGH THE ENTIRE OPTIONS OF LEFT LIST BOX
	for(i=0;i<ResourcesListed.options.length;i++)
	{
		//CHECKING WHETHER ANY ITEM IS SELECTED.
		if(ResourcesListed.options[i].selected)
		{
			//SELECTED ITEM VALUE AND TEXT IS COLLECTED.
			selvalue = ResourcesListed.options[i].value
			seltext = ResourcesListed.options[i].text

			var k = ResourcesSelected.options.length
			var a,arrlen;

			checkFlag = true
			//CHECKING WHETHER THE OTHER LIST BOX IS EMPTY OR NOT,
			//IF EMPTY DIRECTLY PUTTING  THE ITEM IN THE FIRST POSITION,ELSE
			//SORTING THE ELEMENT ACCORDING  TO THEIR VALUE AND THEN
			//DISPLAYING IT THE LIST BOX.
			if(k==0)
			{
				arrlen=0;
				arrLookup[seltext] = selvalue;
				arrTbox[0] = seltext;
			}
			else
			{
				for(a=0;a<k;a++)
				{	//alert("seltext " + seltext + " " + ResourcesSelected.options[a].text)
					if(seltext == ResourcesSelected.options[a].text)
					{
					  //IF THE SELECTED TEXT ALREADY EXIST IN THE RIGHT LIST BOX.
					  //THEN SETTING THE FLAG TRUE.
					    flag=true;

					}
					arrLookup[ResourcesSelected.options[a].text] = ResourcesSelected.options[a].value;
					arrTbox[a] = ResourcesSelected.options[a].text;
				}
				// in the last append the selected item.
				arrlen = arrTbox.length
				if(!flag)
				{
					arrLookup[seltext] = selvalue ;
					arrTbox[arrlen] = seltext ;
				}
				else
				{
					flag = false;
				}
				arrTbox.sort();
			}// end

			for(j=0;j<arrTbox.length;j++)
			{
				//alert("val  " + j + "  " +  arrTbox[j]);
				ResourcesSelected.options[j]=new Option(arrTbox[j],arrLookup[arrTbox[j]],0,0);

			}
			//ResourcesListed.options[i]=null;

		}// if
		else
		{
			//i++;
		}
   }//end of for

	//alerting an error message if item is not selected.
	if(!checkFlag)
	{
		alert("You need to select Resource(s).");
		return false;
	}
}// end of the function


//DELETE FUNCTION

function Delete(obj)
	{

		var selmodbox,selindex,checkflag,ErrStr;
		nameflag = false;
		checkflag = false;
		ErrStr = "";
		if(obj.name=='btnDeleteleadteam')
		{
			selmodbox=document.getElementsByTagName("select")["lstSelected"];
			selindex = selmodbox.options;
			ErrStr = "Resource(s).";
		}

		//alert message when delete button is clicked without selecting a project
		if (selmodbox.length == 0)
		{
			alert("You need to add Resource(s).")
			return false;
		}



		for(i=0;i<selindex.length;i++)
		{

		//CHECKING WHETHER ANY ITEM IS SELECTED.
			if(selmodbox.options[i].selected)
				{
					checkflag = true;
					//var getleadteamidsVal = document.getElementsByTagName("input")["frmAdvanceSearchID"].value
					//alert(getleadteamidsVal);
					selmodbox.options[i] = null;
					i--;
						//alert(document.frmAdvanceSearch.getRemoveId.value)


				}

		}

		//alerting an error message if item is not selected.
		if(!checkflag)
		{
			alert("You need to select "+ErrStr);
			return false;
		}


	}
	function ValidateForm(obj)
	{


		var selmodbox,selindex,checkflag,ErrStr;
		nameflag = false;
		checkflag = false;
		ErrStr = "";
		if(obj.name=='btnsave')
		{
			selmodbox=document.getElementsByTagName("select")["lstSelected"];
			plmodbox = document.getElementsByTagName("select")["lstResources"];
			selindex = selmodbox.options;
			ErrStr = "Resource(s).";
		}

		//alert message when save button is clicked without selecting a resource
		if (plmodbox.length == 0 && selindex.length==0)
		{
			alert("You need to add Resources.")
			return false;
		}

		if (selmodbox.length != 0 )//checking whether any item is present
		{
			for(i=0;i<selindex.length;i++)
			{
				selmodbox.options[i].selected = true;//Selecting All Users By Default
			}
			 return true;
		}
		else
		{
			alert("You need to select Resources.")
			return false;
		}
		return true;

	}
	function ValidateSearch(obj)
		{
			var selmodbox,selindex;
			if(obj.name=='btnSearchResource')
			{
				selmodbox=document.getElementsByTagName("select")["lstSelected"];
				selindex = selmodbox.options;
			}

			if (selmodbox.length != 0 )//checking whether any item is present
			{
				for(i=0;i<selindex.length;i++)
				{
					selmodbox.options[i].selected = true;//Selecting All Users By Default
				}

			}
			 return true;
	}
</script>
